package com.sdu.game.wbr.game_play;

import com.sdu.game.wbr.role_script.*;

import java.util.Collections;
import java.util.List;

public class Room {

    public int daytime = 1;
    public NowTime time;

    public void SetNowTime(NowTime t){
        time = t;
    }

    public RoomType roomType;

    public List<Player> players;

    public Room(){

    }

    public Room(boolean flag){
        setRoomType(flag);
    }

    public Room(boolean flag, List<String> playerList){
        setRoomType(flag);
        initPlayer(playerList);
    }

    /**
     * 设置房间类型
     * @param flag
     */
    public void setRoomType(boolean flag){
        if(flag){
            roomType = RoomType.six_room;
        }
        else{
            roomType = RoomType.nine_room;
        }
    }

    /**
     * 为房间添加玩家
     * @param id
     */
    public void AddPlayer(String id){
        Player player = new Player(id);
    }

    /**
     * 初始化玩家
     * @param playerList
     */
    public boolean initPlayer(List<String> playerList){
        // 列表乱序
        Collections.shuffle(playerList);

        if(roomType == RoomType.six_room){
            if(playerList.size() != 6){
                return false;
            }

            players.add(new Prophet(playerList.get(0)));
            players.add(new Witch(playerList.get(1)));
            players.add(new Wolf(playerList.get(2)));
            players.add(new Wolf(playerList.get(3)));
            players.add(new Player(playerList.get(4), Charactor.villager));
            players.add(new Player(playerList.get(5), Charactor.villager));

        }
        else if(roomType == RoomType.nine_room){
            if(playerList.size() != 9){
                return false;
            }

            players.add(new Prophet(playerList.get(0)));
            players.add(new Witch(playerList.get(1)));
            players.add(new Hunter(playerList.get(2)));
            players.add(new Wolf(playerList.get(3)));
            players.add(new Wolf(playerList.get(4)));
            players.add(new Wolf(playerList.get(5)));
            players.add(new Player(playerList.get(6), Charactor.villager));
            players.add(new Player(playerList.get(7), Charactor.villager));
            players.add(new Player(playerList.get(8), Charactor.villager));

        }
        else{
            return false;
        }

        return true;

    }


    /**
     * 时间环节变更
     */
    public void dayChange(){
        if(time == NowTime.Day){
            time = NowTime.Night;
        }
        else{
            daytime++;
            time = NowTime.Day;
        }
    }



}
